package com.imooc.reader.controller;

import com.imooc.reader.exception.BussiException;
import com.imooc.reader.service.MemberReadStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
@Controller
public class MemberReadStateController {
    @Autowired
    private MemberReadStateService memberReadStateService;

    @RequestMapping("/update_state")
    @ResponseBody
    public Map updateState(Long bookId,Long memberId,Integer state){
        Map map=new HashMap();
        try {
            memberReadStateService.updateState(bookId,memberId,state);
            map.put("code","0");
            map.put("msg","success");
        }catch (BussiException ex){
            ex.printStackTrace();
            map.put("code",ex.getCode());
            map.put("msg",ex.getMsg());
        }
        return map;
    }
}
